/*
* Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef AI_DATATYPE_H
#define AI_DATATYPE_H

#include <cstddef>
#include <cstdint>
#include <vector>
#include <string>
#include <sys/types.h>
/**
 * @brief Defines the basic array structure, which is used to represent various data in the AI subsystem.
 *
 * @since 2.2
 * @version 1.0
 */
template<typename T>
struct Array {
    /* Pointer to the start address of the array */
    T *data;
    /* Array size */
    size_t size;
};

/**
 * @brief Defines the type of framework type id.
 *
 * @since 2.2
 * @version 1.0
 *
 */
typedef enum {
    AI_FRAMEWORK_ID_INVALID=0,
    AI_FRAMEWORK_ID_NCNN=1,
    AI_FRAMEWORK_ID_MNN=2,
    AI_FRAMEWORK_ID_PADDLELITE=3,
    AI_FRAMEWORK_ID_COUNT
}Framework_type;

// Tensor type
typedef enum {
    UINT8 = 0,
    INT8 = 1,
    UINT16 = 2,
    INT16 = 3,
    UINT32 = 4,
    INT32 = 5,
    FLOAT16 = 6,
    FLOAT32 = 7,
    INT64 = 8,
    UINT64 = 9,
}TensorType;

typedef enum {
    NONE = 0,
    NCHW = 1,
    NHWC = 2,
    NCHWC8 = 3,
    ROW_MAJOR = 4,
    LSTM_MTK = 5,
    HWKC = 6,
    HWCK = 7,
    KCHW = 8,
    CKHW = 9,
    KHWC = 10,
    CHWK = 11,
    NC4HW4 = 12,
}TensorLayout;

typedef struct {
    std::string name;
    TensorType type;
    TensorLayout layout;
    std::vector<size_t> shape;
    std::pair<void *, size_t> buffer;
}IOTensor;

typedef enum {
    NET_COMBINED_TYPE = 0,
    NET_TOPO_FILE_TYPE = 1,
    WEIGHT_FILE_TYPE = 2,
}ModelPathType;

typedef struct ModelPathInfo {
    ModelPathType type;
    std::string path;
}ModelPathInfo;

typedef struct ConfigInfo {
    const char *description; // max length is 200, limit by ipc.
} ConfigInfo;

typedef struct ClientInfo { // initialized by ClientInit, don't init manually.
    long long clientVersion; // reserved field

    // generated by server in ClientInit, valid value > 0, INVALID_CLIENT_ID(-1) is invalid, 0 is undefined.
    int clientId;

    // generated by client in ClientInit, valid value > 0, INVALID_SESSION_ID(-1) is invalid, 0 is undefined.
    int sessionId;
    uid_t serverUid; // server's UID, for the sake of share memory transfer.
    uid_t clientUid; // client's UID, for the sake of share memory transfer.
    int extendLen; // reserved field
    unsigned char *extendMsg; // reserved field
} ClientInfo;

typedef struct AlgorithmInfo {
    long long clientVersion; // reserved field
    bool isAsync; // indicate asynchronous
    
    int frameworkType;  // inference framework type id link@Framework_type
 
    std::string algorithmName; // inference neure network name

    long long algorithmVersion; // inference neure network version, default 10000001

    bool isCloud; // reserved field
    int operateId; // reserved field
    int requestId; // identity of algorithm when ClientCallback::OnResult is called. valid only for async algorithm.
    int extendLen; // reserved field
    unsigned char *extendMsg; // reserved field
    std::vector<ModelPathInfo> modelPathInfos;  //Inference network model file path

} AlgorithmInfo;
using IOTensors = std::vector<IOTensor>;

#endif // AI_DATATYPE_H
/** @} */
